//package com.example.springai.langchat;
//
//import dev.langchain4j.community.store.embedding.redis.RedisEmbeddingStore;
//import dev.langchain4j.data.document.Metadata;
//import dev.langchain4j.data.embedding.Embedding;
//import dev.langchain4j.data.segment.TextSegment;
//import dev.langchain4j.model.embedding.EmbeddingModel;
//import dev.langchain4j.model.openai.OpenAiEmbeddingModel;
//import dev.langchain4j.store.embedding.EmbeddingMatch;
//import dev.langchain4j.store.embedding.EmbeddingStore;
//
//import redis.clients.jedis.Jedis;
//
//import java.util.List;
//
//public class zhipuEmbeding {
//    public static void main(String[] args) {
//
//
//        Jedis jedis = new Jedis("127.0.0.1", 6379);
//        jedis.flushDB();  // 清空当前数据库
//
//        EmbeddingStore<TextSegment> embeddingStore = RedisEmbeddingStore.builder()
//                .host("127.0.0.1")
//                .port(6379)
//                .dimension(1024)
//                .build();
//
//        EmbeddingModel embeddingModel = OpenAiEmbeddingModel.builder()
//                .baseUrl("https://open.bigmodel.cn/api/paas/v4")
////                .proxy(new Proxy(Proxy.Type.HTTP,new InetSocketAddress("127.0.0.1", 7890)))
//                .apiKey("13c0fe9af6984455aa087be41fe2f415.Q3ObMb4G6jnP2Jwl").modelName("Embedding-3").logRequests(true).logResponses(true).dimensions(1024)
//                .build();
//
//        TextSegment segment1 = TextSegment.from("张昊越干越猛，鸡巴进出时带出一股股热液，龟头每次顶到最深处都像要捅破她。他突然拔出来，翻过林雪身子，让她趴在桌上，屁股高高撅起。那根湿淋淋的肉棒又插进去，从后面操得更深，卵蛋甩在她阴蒂上，拍得“啪啪”直响。林雪尖叫着高潮，屄里喷出一股水，淅淅沥沥洒在地上。"
//                ,new Metadata().put("time","2025年4月").put("姓名","张昊"));
//        Embedding embedding1 = embeddingModel.embed(segment1).content();
//        embeddingStore.add(embedding1, segment1);
//
////        TextSegment segment2 = TextSegment.from("The weather is good today.");
////        Embedding embedding2 = embeddingModel.embed(segment2).content();
////        embeddingStore.add(embedding2, segment2);
//
//        Embedding queryEmbedding = embeddingModel.embed("张昊").content();
////        embeddingStore.search(queryEmbedding, 1)
//        List<EmbeddingMatch<TextSegment>> relevant = embeddingStore.findRelevant(queryEmbedding, 1);
//        System.out.println("relevant = " + relevant);
//        EmbeddingMatch<TextSegment> embeddingMatch = relevant.get(0);
//        System.out.println("embeddingMatch.embedded().metadata() = " + embeddingMatch.embedded().metadata());
//        System.out.println(embeddingMatch.score()); // 0.8144288659095
//        System.out.println(embeddingMatch.embedded().text()); // I like football.
//
////        redis.stop();
//    }
//
//}
